//
//  JHJTableViewCell.m
//  DayByDay
//
//  Created by dllo on 16/5/13.
//  Copyright © 2016年 dllo. All rights reserved.
//

#import "JHJTableViewCell.h"
#import "ListAndRegionCollectionViewCell.h"

@interface JHJTableViewCell ()<UICollectionViewDataSource, UICollectionViewDelegate>


@property (nonatomic, strong)UILabel *NameLabel;


@end

@implementation JHJTableViewCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        [self createView];
    }
    return self;
}

- (void)setModel:(MusicModel *)model {
    _model = model;
    self.NameLabel.text = _model.name;
    [self.collectionView reloadData];
}

- (void)createView {
    self.NameLabel = [UILabel new];
    [self.contentView addSubview:self.NameLabel];
    self.NameLabel.backgroundColor = [UIColor clearColor];
    UICollectionViewFlowLayout *layout = [UICollectionViewFlowLayout new];
    layout.itemSize = CGSizeMake(WIDTH - 20 / 736.0 * HEIGHT, 80 / 736.0 * HEIGHT);
    layout.minimumInteritemSpacing = 5;
    layout.minimumLineSpacing = 5;
    layout.sectionInset = UIEdgeInsetsMake(10, 10, 10, 10);
    self.collectionView = [[UICollectionView alloc] initWithFrame:self.contentView.frame collectionViewLayout:layout];
    self.collectionView.backgroundColor = [UIColor clearColor];
    self.collectionView.alpha = 0.8;
    [self.contentView addSubview:self.NameLabel];
    [self.contentView addSubview:self.collectionView];
    self.collectionView.dataSource = self;
    self.collectionView.delegate = self;
    [self.collectionView registerClass:[ListAndRegionCollectionViewCell class] forCellWithReuseIdentifier:NSStringFromClass([ListAndRegionCollectionViewCell class])];
    self.backgroundColor = [UIColor clearColor];
}

- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
    return self.model.data.count;
}

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
    ListAndRegionCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:NSStringFromClass([ListAndRegionCollectionViewCell class]) forIndexPath:indexPath];
    cell.model = self.model.data[indexPath.row];
    return cell;
}

- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath {
    self.JHJBlock(self.model.data[indexPath.row], collectionView.tag);
}

- (void)layoutSubviews {
    [super layoutSubviews];
    self.NameLabel.frame = CGRectMake(WIDTH / 4, 10 / 736.0 * HEIGHT, WIDTH / 2, 30 / 736.0 * HEIGHT);
    self.collectionView.frame = CGRectMake(0, 40 / 736.0 * HEIGHT, WIDTH, self.contentView.frame.size.height - 30 / 736.0 * HEIGHT);
    self.NameLabel.textAlignment = 1;
}

- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
